import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

import axios from 'axios'
import VueAxios from 'vue-axios'

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

Vue.use(VueAxios, axios)

Vue.use(ElementUI)

// 前端基准域名
axios.defaults.baseURL = 'http://localhost:8705'
// 前端请求带上认证信息 cookie  header   浏览器控制台 最上面的拦截
axios.defaults.withCredentials = true

// Add a request interceptor  请求拦截器
axios.interceptors.request.use(function (config) {
  // 携带token进行请求 Do something before request is sent
  config.headers.token = store.state.token
  console.log('发送了数据。。。')
  return config
}, function (error) {
  // Do something with request error
  return Promise.reject(error)
})

// Add a response interceptor   响应拦截器
axios.interceptors.response.use(function (response) {
  // Do something with response data
  console.log('收到了数据。。。')
  return response
}, function (error) {
  // Do something with response error
  return Promise.reject(error)
})

// 阻止 vue 在启动时生成生产 无用 提示   浏览器控制台 最下面的拦截
Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
